<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>SSHチケット販売管理画面</title>
	<link href="/resources/css/admin.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="/resources/js/jquery.js"></script>
	<script type="text/javascript" src="/resources/js/jquery.ajax.js"></script>
	<script type="text/javascript">
		function search() {
			jQuery("#isExcel").val("");
			jQuery("#isSearch").val("Y");
			jQuery('#searchFrm').attr('action','/admin/ticketList.do').submit();
		}

		function downExcel(){
			$("#isExcel").val("Y");
			$("#isSearch").val("");
			jQuery('#searchFrm').attr('action','/admin/ticketList.do').submit();
		}

		function cancel() {
			jQuery("#userNm").val("");
			jQuery("#userHnm").val("");
			jQuery("#userEmail").val("");
			jQuery("#phone").val("");
			jQuery("#payState").val("");
			jQuery("#mailState").val("");
			jQuery("#addr1").val("");
			jQuery("#addr2").val("");
			jQuery("#addr3").val("");
			jQuery("#isSearch").val("");
		}

		function goPage(currentPage){
			jQuery("#isExcel").val("");
			if(jQuery("#isSearch").val() == 'Y') {
				jQuery('#searchFrm').attr({'action':'/admin/ticketList.do?page='+currentPage}).submit();
			} else {
				location.href="/admin/ticketList.do?page="+currentPage;
			}
		}

		function view(seq) {
			location.href="/admin/ticketDetail.do?seq="+seq;
		}
		
		function updatePay() {
			var _num = 0;
			var _param = "";
			var _sp=",";
			jQuery('input:checkbox[name="_seq"]').each(function() {
				if(this.checked) {
					_param += _sp + this.value;
					_num++;
				}
			});
			if(_num>0) {
				if(confirm("入金済みでのチェックを行いますか?")) {
					var param = {
						user_seq : _param.substring(1)
					};

					ajaxToJSON("/admin/updatePayState.do", param, function(data) {
						switch(data.result) {
							case 'OK':
								alert("完了");
								document.location.reload();
								break;
							default:
								alert(data.errorMsg);
								break;
						}
					});
				}
			}else{
				alert("対象を選択してください。");
			}
		}
		
		function sendMail(flag) {
			var _seq = flag;
			if(_seq != '') {
				if(confirm("メール転送を行いますか?")) {
					var param = {
						user_seq : _seq
					};

					ajaxToJSON("/admin/sendMail.do", param, function(data) {
						switch(data.result) {
							case 'OK':
								alert("完了");
								document.location.reload();
								break;
							default:
								alert(data.errorMsg);
								break;
						}
					});
				}
			}
		}
		
		
		function logOut() {
			var param = {
			};
			ajaxToJSON("/admin/logout.do", param, function(data) {
				jQuery(location).attr("href", "/admin/loginForm.do");
			});
		}
	</script>
</head>
<body>

<!--[if IE 7 ]><body class="ie7 legacy-ie"> <![endif]-->
<!--[if IE 8 ]><body class="ie8 legacy-ie"> <![endif]-->
<!--[if IE 9 ]><body class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><body><!--<![endif]-->
<div id="container">
	<h1>SHIN SEUNG HUN LIVE IN TOKYO</h1>

	<div id="subheader">
		<p>ID : admin /
		<a href="#" onclick="logOut();return false;">Logout</a></p>
	</div>

	<!-- content -->
	<div id="content">
	
	
		<!-- 검색폼 -->
		<h2>登録情報検索</h2>
		
		
		<form id="searchFrm" name="searchFrm" method="post">
		<input type="hidden" name="isSearch" id="isSearch" value="${SearchMap.isSearch}"/>
		<input type="hidden" name="isExcel" id="isExcel" value=""/>
		<table class="tbl-type1 mgt5">
		<colgroup>
			<col width="15%" /><col width="18%"><col width="15%" /><col width="18%"><col width="15%" /><col width="19%">
		</colgroup>
		<tr>
			<th>お名前</th>
			<td><input type="text" size="25" id="userNm" name="userNm" value="${SearchMap.userNm}" onkeydown="if(event.keyCode==13) javascript:search();"/></td>
			<th>メール</th>
			<td>
				<input type="text" size="20" id="userEmail" name="userEmail" value="${SearchMap.userEmail}" onkeydown="if(event.keyCode==13) javascript:search();"/>
			</td>
			<th>転送</th>
			<td>
				<select id="mailState" name="mailState">
					<option value=""></option>
					<option value="N" <c:if test="${SearchMap.mailState eq 'N'}">selected</c:if>>未転送</option>
					<option value="Y" <c:if test="${SearchMap.mailState eq 'Y'}">selected</c:if>>転送</option>
				</select>
			</td>
		</tr>
		<tr>
			<th>フリガナ</th>
			<td><input type="text" size="25" id="userHnm" name="userHnm" value="${SearchMap.userHnm}" onkeydown="if(event.keyCode==13) javascript:search();"/></td>
			<th>TEL</th>
			<td><input type="text" size="25" id="phone" name="phone" value="${SearchMap.phone}" onkeydown="if(event.keyCode==13) javascript:search();"/></td>
			<th>状況</th>
			<td>
				<select id="payState" name="payState">
					<option value=""></option>
					<option value="N" <c:if test="${SearchMap.payState eq 'N'}">selected</c:if>>未入金</option>
					<option value="Y" <c:if test="${SearchMap.payState eq 'Y'}">selected</c:if>>入金</option>
				</select>
			</td>
		</tr>
		<tr>
			<th>都道府県</th>
			<td>
				<select id="addr1" name="addr1">
					<option value=""></option>
					<c:forEach var="addr1" items="${addrList}">
						<option value="${addr1}" <c:if test="${SearchMap.addr1 eq addr1}">selected</c:if>>${addr1}</option>
					</c:forEach>
				</select>
			</td>
			<th>郡市区</th>
			<td>
				<input type="text" size="20" id="addr2" name="addr2" value="${SearchMap.addr2}" onkeydown="if(event.keyCode==13) javascript:search();"/>
			</td>
			<th>その以下</th>
			<td><input type="text" size="20" id="addr3" name="addr3" value="${SearchMap.addr3}" onkeydown="if(event.keyCode==13) javascript:search();"/></td>
		</tr>
		</table>
		</form>
		<!-- //검색폼 -->
		
		<!-- 중앙버튼 -->
		<div class="btn_area c">
			<button type="button" class="btn1" onclick="search();return false;">検索</button>
			<button type="button" class="btn1" onclick="cancel();return false;">クリア</button>
		</div>
		<!-- //중앙버튼 -->
		
		<hr />		<!-- 구분선(여백) -->
	
	
		<div class="board_top clr">
			<div class="fr">
				全て: ${SearchMap.totalCount}件
				<c:if test="${SearchMap.totalCount>0}">
				|
				リストダウン <button type="button" class="btn2" class="xls" onclick="downExcel();return false;">CSV</button>
				</c:if>
			</div>
		</div>

		<table class="tbl-type2 mgt5">
		<colgroup>
		<col width="75" /><col width="150" /><col width="150" /><col width="*" /><col width="200" /><col width="200" /><col width="80" /><col width="80" /><col width="80" /><col width="80" /><col width="80" />
		</colgroup>
			<thead>
				<tr>
					<th>選択</th>
					<th>漢字表記</th>
					<th>フリガナ</th>
					<th>住所</th>
					<th>TEL</th>
					<th>メール</th>
					<th>1公演</th>
					<th>2公演</th>
					<th>金額</th>
					<th>状況</th>
					<th>メール転送</th>
				</tr>
			</thead>
			<tbody>
				<!-- looping block -->
				<c:forEach items="${ticketList}" var="ticketList" varStatus="status">
					<tr onmouseover="bgColor='#fff4ff'" onmouseout="bgColor='#ffffff'" style="cursor:hand;" onclick="javascript:view('${ticketList.seq}');">
					    <td onclick="event.cancelBubble=true;"><input type="checkbox" name="_seq" value="${ticketList.seq}"/></td>
	<%-- 				    <td width="30">${SearchMap.totalCount - (SearchMap.num - 1) * SearchMap.listLimit - status.index}</td> --%>
					    <td>${ticketList.userNameF} ${ticketList.userNameS}</td>
					    <td>${ticketList.hiraganaF} ${ticketList.hiraganaS}</td>
					    <td>${ticketList.addr1} ${ticketList.addr2} ${ticketList.addr3}</td>
					    <td>${ticketList.phone}</td>
					    <td>${ticketList.userEmail}</td>
					    <td>${ticketList.onceTicket}</td>
					    <td>${ticketList.twiceTicket}</td>
					    <td>${ticketList.price}</td>
					    <td>
					    	<c:if test="${ticketList.payState eq 'N'}">
					    		未入金
					    	</c:if>
					    	<c:if test="${ticketList.payState eq 'Y'}">
					    		入金
					    	</c:if>
					    </td>
					    <td onclick="event.cancelBubble=true;">
					    	<c:if test="${ticketList.mailYn eq 'N'}">
					    		<button type="button" onclick="sendMail('${ticketList.seq}');return false;">MAIL</button>
					    	</c:if>
					    	<c:if test="${ticketList.mailYn eq 'Y'}">
					    		転送
					    	</c:if>
					    </td>
					</tr>
				</c:forEach>
	
				<c:if test="${empty ticketList}">
				<tr>
					<td colspan="11">
				  		<spring:message code="common.nodata.msg" />
				  	</td>
				</tr>
				</c:if>
			</tbody>
		</table>
		

		<!-- 페이징 -->
		<div class="paging">
			${paging}
		<!-- 
			<button type="button" class="btn_first">&lt;&lt;</button>
			<button type="button" class="btn_prev">&lt;</button>
			<a href="#">1</a>
			<a href="#">2</a>
			<span class="current">3</span>
			<a href="#">4</a>
			<a href="#">5</a>
			<a href="#">6</a>
			<a href="#">7</a>
			<a href="#">8</a>
			<a href="#">9</a>
			<a href="#">10</a>
			<button type="button" class="btn_next">&gt;&gt;</button>
			<button type="button" class="btn_last">&gt;</button>
		 -->
		</div>
		<!-- //페이징 -->
				
		<!-- 중앙버튼 -->
		<div class="btn_area c">
			<button type="button" class="btn1" onclick="updatePay();return false;">入金確認</button>
		</div>
		<!-- //중앙버튼 -->
	
	</div>
	<!-- //content -->
</div>

</body>
</html>